//
//  SLPageManager.m
//  SLPageView
//
//  Created by 王胜利 on 2018/11/12.
//  Copyright © 2018 wsl. All rights reserved.
//  分页组件标题和内容区域关联器
//

#import "SLPageManager.h"

@implementation SLPageEntity

@end

@implementation SLPageManager

/// MAKR: - 关联page标题栏和内容区域
+ (void)managerWithTitleView:(id<SLPageProtocol>)titleView contentView:(id<SLPageContentProtocol>)contentView pageEntitys:(NSArray <SLPageEntity *>*)pageEntitys defaultIdx:(NSInteger)defaultIdx{

    titleView.titleBtnSelect = ^(NSInteger idx) {
        [contentView scrollToIndex:idx animated:YES];
    };

    contentView.didScrollToIdx = ^(NSInteger idx) {
        [titleView scrollToIndex:idx animated:NO];
    };


    titleView.pageEntitys = pageEntitys;

    NSMutableArray *views = @[].mutableCopy;
    for (SLPageEntity *entity in pageEntitys) {
        [views addObject:entity.childView];
    }

    contentView.childViews = views;


    [(UIView *)titleView layoutIfNeeded];
    [(UIView *)contentView layoutIfNeeded];

    [titleView scrollToIndex:defaultIdx animated:NO];
    [contentView scrollToIndex:defaultIdx animated:NO];
}

@end
